from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-02 14:03:27.963374
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 02, Oct, 2022
Time: 14:03:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5786
Nobs: 797.000 HQIC: -50.9040
Log likelihood: 10278.1 FPE: 6.37464e-23
AIC: -51.1071 Det(Omega_mle): 5.69795e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298961 0.053059 5.634 0.000
L1.Burgenland 0.108667 0.035647 3.048 0.002
L1.Kärnten -0.106486 0.018970 -5.613 0.000
L1.Niederösterreich 0.209070 0.074521 2.806 0.005
L1.Oberösterreich 0.101484 0.071572 1.418 0.156
L1.Salzburg 0.252517 0.038014 6.643 0.000
L1.Steiermark 0.037413 0.049734 0.752 0.452
L1.Tirol 0.106475 0.040309 2.641 0.008
L1.Vorarlberg -0.059082 0.034657 -1.705 0.088
L1.Wien 0.055367 0.063947 0.866 0.387
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064009 0.109936 0.582 0.560
L1.Burgenland -0.033446 0.073859 -0.453 0.651
L1.Kärnten 0.047795 0.039306 1.216 0.224
L1.Niederösterreich -0.171549 0.154403 -1.111 0.267
L1.Oberösterreich 0.384526 0.148293 2.593 0.010
L1.Salzburg 0.287665 0.078764 3.652 0.000
L1.Steiermark 0.106273 0.103046 1.031 0.302
L1.Tirol 0.313651 0.083519 3.755 0.000
L1.Vorarlberg 0.025090 0.071808 0.349 0.727
L1.Wien -0.017343 0.132494 -0.131 0.896
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190103 0.027258 6.974 0.000
L1.Burgenland 0.090053 0.018313 4.918 0.000
L1.Kärnten -0.008461 0.009745 -0.868 0.385
L1.Niederösterreich 0.264137 0.038283 6.900 0.000
L1.Oberösterreich 0.126769 0.036768 3.448 0.001
L1.Salzburg 0.047677 0.019529 2.441 0.015
L1.Steiermark 0.016757 0.025549 0.656 0.512
L1.Tirol 0.094261 0.020708 4.552 0.000
L1.Vorarlberg 0.059302 0.017804 3.331 0.001
L1.Wien 0.120439 0.032851 3.666 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109055 0.027914 3.907 0.000
L1.Burgenland 0.044569 0.018754 2.377 0.017
L1.Kärnten -0.016111 0.009980 -1.614 0.106
L1.Niederösterreich 0.193661 0.039205 4.940 0.000
L1.Oberösterreich 0.293524 0.037653 7.795 0.000
L1.Salzburg 0.115202 0.019999 5.760 0.000
L1.Steiermark 0.100163 0.026165 3.828 0.000
L1.Tirol 0.116262 0.021206 5.482 0.000
L1.Vorarlberg 0.070756 0.018233 3.881 0.000
L1.Wien -0.027364 0.033642 -0.813 0.416
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128936 0.050619 2.547 0.011
L1.Burgenland -0.051543 0.034008 -1.516 0.130
L1.Kärnten -0.040196 0.018098 -2.221 0.026
L1.Niederösterreich 0.170924 0.071094 2.404 0.016
L1.Oberösterreich 0.138606 0.068280 2.030 0.042
L1.Salzburg 0.285838 0.036266 7.882 0.000
L1.Steiermark 0.034228 0.047447 0.721 0.471
L1.Tirol 0.163747 0.038456 4.258 0.000
L1.Vorarlberg 0.104145 0.033063 3.150 0.002
L1.Wien 0.067610 0.061006 1.108 0.268
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060439 0.040148 1.505 0.132
L1.Burgenland 0.038256 0.026973 1.418 0.156
L1.Kärnten 0.050600 0.014354 3.525 0.000
L1.Niederösterreich 0.225174 0.056387 3.993 0.000
L1.Oberösterreich 0.281944 0.054155 5.206 0.000
L1.Salzburg 0.050671 0.028764 1.762 0.078
L1.Steiermark -0.006650 0.037632 -0.177 0.860
L1.Tirol 0.149941 0.030500 4.916 0.000
L1.Vorarlberg 0.071322 0.026224 2.720 0.007
L1.Wien 0.079228 0.048386 1.637 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179205 0.047998 3.734 0.000
L1.Burgenland -0.005906 0.032247 -0.183 0.855
L1.Kärnten -0.061123 0.017161 -3.562 0.000
L1.Niederösterreich -0.083611 0.067412 -1.240 0.215
L1.Oberösterreich 0.192497 0.064745 2.973 0.003
L1.Salzburg 0.056728 0.034388 1.650 0.099
L1.Steiermark 0.230688 0.044990 5.128 0.000
L1.Tirol 0.493678 0.036464 13.539 0.000
L1.Vorarlberg 0.049532 0.031351 1.580 0.114
L1.Wien -0.049355 0.057847 -0.853 0.394
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161105 0.055104 2.924 0.003
L1.Burgenland -0.010976 0.037021 -0.296 0.767
L1.Kärnten 0.066000 0.019702 3.350 0.001
L1.Niederösterreich 0.200943 0.077393 2.596 0.009
L1.Oberösterreich -0.061593 0.074331 -0.829 0.407
L1.Salzburg 0.215486 0.039480 5.458 0.000
L1.Steiermark 0.113913 0.051651 2.205 0.027
L1.Tirol 0.076631 0.041863 1.831 0.067
L1.Vorarlberg 0.124513 0.035993 3.459 0.001
L1.Wien 0.116172 0.066412 1.749 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354730 0.032020 11.078 0.000
L1.Burgenland 0.006024 0.021512 0.280 0.779
L1.Kärnten -0.023573 0.011448 -2.059 0.039
L1.Niederösterreich 0.223482 0.044972 4.969 0.000
L1.Oberösterreich 0.176039 0.043192 4.076 0.000
L1.Salzburg 0.047349 0.022941 2.064 0.039
L1.Steiermark -0.018321 0.030013 -0.610 0.542
L1.Tirol 0.108741 0.024326 4.470 0.000
L1.Vorarlberg 0.073368 0.020915 3.508 0.000
L1.Wien 0.053414 0.038591 1.384 0.166
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041122 0.151983 0.191337 0.157091 0.125040 0.113232 0.065948 0.225656
Kärnten 0.041122 1.000000 -0.002578 0.129657 0.041451 0.096213 0.429774 -0.053154 0.101512
Niederösterreich 0.151983 -0.002578 1.000000 0.337466 0.154908 0.300673 0.110636 0.183553 0.327219
Oberösterreich 0.191337 0.129657 0.337466 1.000000 0.232159 0.333503 0.172703 0.172371 0.264394
Salzburg 0.157091 0.041451 0.154908 0.232159 1.000000 0.146516 0.126839 0.148899 0.136333
Steiermark 0.125040 0.096213 0.300673 0.333503 0.146516 1.000000 0.153310 0.140784 0.080456
Tirol 0.113232 0.429774 0.110636 0.172703 0.126839 0.153310 1.000000 0.114751 0.154580
Vorarlberg 0.065948 -0.053154 0.183553 0.172371 0.148899 0.140784 0.114751 1.000000 0.007193
Wien 0.225656 0.101512 0.327219 0.264394 0.136333 0.080456 0.154580 0.007193 1.000000